/*================================================================
*   文件名称：main.cpp
*   创 建 者：yang qiang
*   创建日期：2020年04月01日
*   版    本：v1.0.0
*   描    述：
*   Copyright (C) 2020 All rights reserved.
*   
* ================================================================*/


#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;

vector<string> subdomainVisits(vector<string>& cpdomains) {
    unordered_map<string, int> c;
    for (auto cd : cpdomains) {
        int i = cd.find(" ");
        int n = stoi(cd.substr (0, i));
        string s = cd.substr (i + 1);
        for (int i = 0; i < s.size(); ++i)
            if (s[i] == '.')
                c[s.substr(i + 1)] += n;
        c[s] += n;
    }
    vector<string> res;
    for (auto k : c)
        res.push_back (to_string(k.second) + " " + k.first);
    return res;
}